<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-mpMerchantWallet-edit" th:object="${mpMerchantWallet}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
            <input id="merchantId" name="merchantId" th:field="*{merchantId}"  type="hidden">
            <input id="walletKindId" name="walletKindId" th:field="*{walletKindId}"  type="hidden">
			<div class="form-group">
				<label class="col-sm-3 control-label">商户名称：</label>
				<div class="col-sm-8">
					<input id="merchantName" name="merchantName" th:field="*{merchantName}" class="form-control" type="text" readonly>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">钱包类型：</label>
				<div class="col-sm-8">
					<input id="walletKindName" name="walletKindName" th:field="*{walletKindName}" class="form-control" type="text" readonly>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">余额(元)：</label>
				<div class="col-sm-8">
					<input id="accountBalance" name="accountBalance"  class="form-control" type="text" readonly>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">待结算金额(元)：</label>
				<div class="col-sm-8">
					<input id="waitLiquidatedBalance" name="waitLiquidatedBalance"  class="form-control" type="text" readonly>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">冻结金额(元)：</label>
				<div class="col-sm-8">
					<input id="frozenBalance" name="frozenBalance"  class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">未结算金额(元)：</label>
				<div class="col-sm-8">
					<input id="unliquidatedBalance" name="unliquidatedBalance"  class="form-control" type="text" readonly>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">D0：</label>
				<div class="col-sm-8">
					<input id="dZero" name="dZero" th:field="*{dZero}" class="form-control" type="text">
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script th:inline="javascript">
        	var prefix = ctx + "merchant/wallet";
			var $from = $("#form-mpMerchantWallet-edit")
			var mpMerchantWallet = [[${mpMerchantWallet}]];
            // 总金额
            var accountBalance = new Decimal(mpMerchantWallet.accountBalance).div(new Decimal(100));
            $from.find("input[name='accountBalance']").val(accountBalance);
            // 待结算金额
			var waitLiquidatedBalance = new Decimal(mpMerchantWallet.waitLiquidatedBalance).div(new Decimal(100));
            $from.find("input[name='waitLiquidatedBalance']").val(waitLiquidatedBalance);
			// 冻结金额
            var frozenBalance = new Decimal(mpMerchantWallet.frozenBalance).div(new Decimal(100));
            $from.find("input[name='frozenBalance']").val(frozenBalance);
			// 未结算金额
            var unliquidatedBalanceOne = new Decimal(mpMerchantWallet.unliquidatedBalanceOne).div(new Decimal(100));
            var unliquidatedBalanceTwo = new Decimal(mpMerchantWallet.unliquidatedBalanceTwo).div(new Decimal(100));
			var unliquidatedBalance = new Decimal(unliquidatedBalanceOne).add(new Decimal(unliquidatedBalanceTwo)).toFixed(2);
            $from.find("input[name='unliquidatedBalance']").val(unliquidatedBalance);


			// 表单校验
			$.validator.addMethod("regex",function (value, element, params) {
				var exp = new RegExp(params);
				return exp.test(value);
			},"小于等于1(可保留四位小数)");
            /*校验规则*/
            $.validator.addMethod("regex2",function (value, element, params) {
                var exp = new RegExp(params);
                return exp.test(value);
            },"请输入数字(可保留两位小数)");
            $from.validate({
				rules:{
                    dZero:{
						required:true,
                        regex:"^(0(\\.\\d{1,4})?|1(\\.0{1,4})?)$"
					},
                    frozenBalance:{
                        regex2:"^[0-9]+(.[0-9]{2}|.[0-9]{1})?$"
                    }
				},
				focusCleanup: true
			});
		function submitHandler() {
			if ($.validate.form()) {
                var data = $from.serializeArray();
				// 冻结金额
                data[5].value = new Decimal(data[5].value).mul(new Decimal(100));
                // D0
                data[7].value = new Decimal(data[7].value).mul(new Decimal(100));

                $.operate.save(prefix + "/edit", data);

			}
		}

	</script>
</body>
</html>
